package cn.ffcs.tmp.dao;

import java.util.Date;

import cn.ffcs.base.dao.BaseDAO;
import cn.ffcs.base.model.BaseEntity;
import cn.ffcs.security.model.User;
import cn.ffcs.tmp.model.Annex;
import cn.ffcs.util.context.ApplicationContextUtil;

/**
 * 
 * 附件DAO实现<br/> <table>
 * <tr>
 * <td>负责人/principal: </td>
 * <td colspan="2">pany</td>
 * <tr>
 * <td>修改记录/revision:</td>
 * <td colspan="2"></td>
 * </tr>
 * <tr>
 * <td>日期:</td>
 * <td>修改人:</td>
 * <td>修改说明:</td>
 * </tr>
 * <tr>
 * <td></td>
 * <td></td>
 * <td></td>
 * </tr>
 * </table>
 * @author pany
 * @version $Id$
 */

public class AnnexDAO<A extends Annex> extends BaseDAO<A> implements
        IAnnexDAO<A>
{

    public String getEntityName()
    {
        return new Annex().getClass().getName();
    }
    
    
    /**
     * 删除所有附件
     * @param b
     * @return
     */
    public void deleteAttachByEntity(BaseEntity entity){
        getSession().createQuery("delete from Attach a where a.refEntity='"+entity.getClass().getName()+"' AND a.refEntityID="+entity.getId()).executeUpdate();
    }
    
    public void saveAnnex(A baseEntity){
        if (baseEntity != null)
        {
            if (baseEntity.getId() == null || baseEntity.getId() == 0)
            {   
                //设置操作人
                baseEntity.setCreator("listener");
                //设置有效时间
                baseEntity.setBegin(this.getCurrSysdate());
                Long l=Long.valueOf("9783941568000");
                Date end=new Date(l);
                baseEntity.setEnd(end);
                //保存数据
                super.save(baseEntity);
            }
            else
            {
                super.update(baseEntity);
            }
        }
    }
        
}
